package com.zbcx.generate.mbtiles;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import javax.swing.JTable;
/**
 * 选择文件夹<br/>
 * @author zbcx
 *
 */
public class FileChooser extends JFrame implements ActionListener {

	private JButton open = null;
	
	private String filePath = null;

	private GenerateMbtiles generateMbtiles;

	public FileChooser() {
		generateMbtiles = new GenerateMbtiles();
		open = new JButton("请选择wms文件夹");
		
		this.setTitle("WMS文件转MBTILES");
		this.add(open);
		this.setSize(500,500);  
		open.setBounds(400, 200, 400, 400);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		open.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		JFileChooser jfc = new JFileChooser();
		jfc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
		jfc.showDialog(new JLabel(), "请选择wms文件夹");
		File file = jfc.getSelectedFile();
		if (file.isDirectory()) {
			filePath = file.getAbsolutePath();
			if (filePath.contains("wms")) {
				open.setText("正在处理请稍后...");
				generateMbtiles.listPathFiles(open, filePath);
			} else {
				open.setText("不是wms文件夹");
			}
		} else if (file.isFile()) {
			open.setText("不是wms文件夹");
		}
	}

}
